package chapter20;


import java.util.Comparator;

/**
 * @program: exercise
 * @description: 给出了一个方法，返回2个几何对象中较大的那个。2个对象使用GeometricObjdectComparator进行比较
 * @author: 陈庆彪
 * @create: 2020-02-22 11:07
 **/
public class TestComparator {
    public static void main(String[] args) {
//        GeometricObject g1=Rectangle.builder().height(5.0).width(5.0).build();
//        GeometricObject g2=Circle.builder().radius(5.0).build();
        GeometricObject g1= new Rectangle(5.0,5.0);
        GeometricObject g2=new Circle(5.0);
        GeometricObject g= max(g1,g2,new GeometricObjectCompartor());

        System.out.println("the area of the lager object is "+g.getArea());
    }


    private static GeometricObject max(GeometricObject g1, GeometricObject g2, Comparator<GeometricObject> c) {
        if (c.compare(g1,g2)>0)
            return g1;
        else
            return g2;
    }


}
